package collect.taobao.util.generate;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public class FreezeDaoImpl extends HibernateDaoSupport implements FreezeDao{
	public int save(EntityBean entityBean) {
		int i=0;
		Session session =null;
		try{
			session = this.getSession();
	        Transaction trans = session.beginTransaction();
			this.getHibernateTemplate().save(entityBean);
			trans.commit();   
			i=1;
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			if(session!=null)session.close();
		}
		return i;
	}
	public int delete(EntityBean entityBean) {
		int i=0;
		Session session =null;
		try{
			session = this.getSession();
	        Transaction trans = session.beginTransaction();
			this.getHibernateTemplate().delete(entityBean);
			trans.commit();   
			i=1;
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			if(session!=null)session.close();
		}
		return i;
	}

	public int update(EntityBean entityBean) {
		int i=0;
		Session session =null;
		try{
			session = this.getSession();
	        Transaction trans = session.beginTransaction();
			this.getHibernateTemplate().update(entityBean);
			trans.commit();   
			i=1;
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			if(session!=null)session.close();
		}
		return i;
	}
	
	public List queryList() {
		return this.getHibernateTemplate().loadAll(EntityBean.class);
	}

	public EntityBean query(String id) {
		Session session =null;
		EntityBean  entityBean = null;
		try{
			session = this.getSession();
			entityBean = (EntityBean)session.load(EntityBean.class, new Integer(id)); 
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			if(session!=null)session.close();
		}
		return entityBean;
	}
}
